String.prototype.trim = function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};
(function(){
 var _destroyContainer =null;
 var _createContainer =null;
 if(typeof(Ogo) == "undefined" ){
    Ogo={};var O = Ogo;
    O.global = this;
    O.doc = window["document"] || null;
    O.version ={major: 0, minor: 1, patch: 0, flag: "",toString:function(){return this.major + "." + this.minor + "." + this.patch + this.flag ;}}
   if(document.all){
    O.isIE = parseFloat(navigator.appVersion.split("MSIE ")[1]) || undefined;
    var t_mode = document.documentMode;
    if(t_mode && t_mode != 5 && Math.floor(O.isIE) != t_mode){O.isIE = t_mode;}
   }
    O.isChrome = parseFloat(navigator.userAgent.split("Chrome ")[1]) || undefined;
    O.isFF = parseFloat(navigator.userAgent.split("Firefox/")[1] || navigator.userAgent.split("Minefield/")[1]) || undefined;
 } 
O.body = function(){return dojo.doc.body || dojo.doc.getElementsByTagName("body")[0];}
O.ready=function(inFun){if(  typeof(inFun) =="function" ){O.doc.addEventListener("DOMContentLoaded", inFun, false);}}
O.byId=function(inID,inDoc){return (typeof(inID) == "string") ? (inDoc || O.doc).getElementById(inID):inID;}
O.find = function(inQuery,inNode){
var t_el = typeof(inNode)=="undefined"?O.doc:O.byId(inNode);t_el = t_el==null?O.doc:t_el;
return t_el.querySelectorAll(inQuery);
}
O.bind =function(inNode,inEventName,inDaOrFnA,inDaOrFnB){
    var t_fun = typeof(inDaOrFnA)=="function"?inDaOrFnA:inDaOrFnB;
    var t_data = typeof(inDaOrFnA)=="function"?inDaOrFnB:inDaOrFnA;
    var t_packageFn = function(e){t_fun(e,t_data);}
    O.byId(inNode).addEventListener(inEventName, t_packageFn, false);
}
O.unbind =function(inNode,inEventName,inFun){
    O.byId(inNode).removeEventListener(inEventName, inFun, false);
}
O.style =function(inNode,inStyle,inValue){
    var t_node = O.byId(inNode);
    if( typeof(inStyle) == "object"){
       for(var _key in inStyle){
           t_node.style[_key] = inStyle[_key];
       } 
       return true;
    }
    if(inValue == undefined){return t_node.style[inStyle];}
    t_node.style[inStyle] = inValue;
    return true;
}
O.getChildNodes = function(inNode){
    var t_cns =[];
    for(var i=0;i<inNode.childNodes.length;i++){
        if( inNode.childNodes[i].tagName ){t_cns.push(inNode.childNodes[i])}
    }
    return t_cns; 
}
O.getNodeAt =function(inNode,inIndex){
    return O.getChildNodes(inNode)[inIndex];
}
O.nextSibling =function(inNode){
  var t_node= O.byId(inNode).nextSibling;
  while (t_node.nodeType!=1){t_node=t_node.nextSibling;}
  return t_node;
}
O.place = function (inNode, inRefNode, inPosition){
    var t_node =  O.byId(inNode);
    var t_refNode = O.byId(inRefNode);
    
    function _insertBefore(inNode, inRefNode){
        var t_parent = inRefNode.parentNode;
        if(t_parent){
            t_parent.insertBefore(inNode, inRefNode);
        }
    }
    function _insertAfter(inNode, inRefNode){
        var t_parent = inRefNode.parentNode;
        if(t_parent){
            if(t_parent.lastChild == inRefNode){
                t_parent.appendChild(inNode);
            }else{
                t_parent.insertBefore(inNode, O.nextSibling(inRefNode));
            }
        }
    }
    if(typeof inPosition == "number"){ 
        var t_cns =  O.getChildNodes(t_refNode);
        if(!t_cns.length || t_cns.length <= inPosition){
                t_refNode.appendChild(t_node);
        }else{
                _insertBefore(t_node, t_cns[inPosition < 0 ? 0 : inPosition]);
        }
    }else{
        switch(inPosition){
            case "before":
                    _insertBefore(t_node, t_refNode);
                    break;
            case "after":
                    _insertAfter(t_node, t_refNode);
                    break;
            case "replace":
                    t_refNode.parentNode.replaceChild(t_node, t_refNode);
                    break;
            case "only":
                    O.empty(t_refNode);
                    t_refNode.appendChild(t_node);
                    break;
            case "first":
                    if(t_refNode.firstChild){
                        _insertBefore(t_node, t_refNode.firstChild);
                        break;
                    }
            default:
                    t_refNode.appendChild(t_node);
        }
    }
    return t_node;
}
O.create =function(inNode,inAttrs,inRefNode,inPosition){
    if(inRefNode){
        inRefNode = O.byId(inRefNode);
    }
    if(typeof inNode == "string"){
        inNode = inNode.trim();
        if(inNode.indexOf("<") == 0 ){
            if(_createContainer==null ){_createContainer = O.doc.createElement("div");}
            _createContainer.innerHTML = inNode;
            inNode = O.getNodeAt(_createContainer,0);
        }else{inNode =  O.doc.createElement(inNode);}
    }
    if(inAttrs){ O.attr(inNode, inAttrs); }
    if(inRefNode){O.place(inNode, inRefNode, inPosition);}
}
O.destroy = function(inNode){
    var t_node = O.byId(inNode);
    if(_destroyContainer == null){_destroyContainer = O.doc.createElement("div");}
    _destroyContainer.appendChild(t_node.parentNode ? t_node.parentNode.removeChild(t_node) : t_node);
    _destroyContainer.innerHTML = "";
}
O.empty = function(inNode){
    O.byId(inNode).innerHTML = "";
}
O.attr = function(inNode,inAttr, inValue){
    inNode = O.byId(inNode);
    if( typeof(inAttr) == "string" && inValue == undefined){
        return inNode.getAttribute(inAttr);
    }
    if( typeof(inAttr) == "object"  ){
        for(var _key in inAttr){
             O.attr(inNode, _key, inAttr[_key] );
        }
        return inNode;
    }
    if(inAttr == "style" && typeof(inValue)!= "string"){
	O.style(inNode, inValue);
        return inNode;
    }
    if( inAttr == "innerHTML"){
        inNode.innerHTML = inValue;
        return inNode;
    }
    inNode.setAttribute(inAttr, inValue);
    return inNode;
}
O.hasAttr =function(inNode,inAttrName){
    inNode = O.byId(inNode);
    var t_attr = inNode.getAttributeNode && inNode.getAttributeNode(inAttrName);
    return t_attr && t_attr.specified;
}
O.removeAttr = function(inNode,inAttrName){O.byId(inNode).removeAttribute(inAttrName);}
O.hasClass =function(inNode,inClassName){
    return ((" "+ O.byId(inNode)["className"] +" ").indexOf(" " + inClassName + " ") >= 0); 
}
function str2array(inStr){
        if(typeof inStr == "string" || inStr instanceof String){
            if(inStr.indexOf(" ") < 0){
                var t_a1 = new Array(); t_a1[0] = inStr;
                return t_a1;
            }else{
              return inStr.split(/\s+/);
            }
        }
        return inStr || "";
   }
O.addClass=function(inNode,inClassName){
   inNode = O.byId(inNode);
   var t_classStr = str2array(inClassName);
   var t_cls = inNode["className"] ? " " + inNode["className"] + " " : " ";
   var t_oldLen = t_cls.length;
   var t_c; 
   for(var i = 0; i < t_classStr.length; i++){
        t_c = t_classStr[i];
        if(t_c && t_cls.indexOf(" " + t_c + " ") < 0){
                t_cls += (t_c+" ");
        }
    }
    if(t_oldLen < t_cls.length){
        inNode["className"] = t_cls.substr(1, t_cls.length - 2);
    }
    return inNode;
}
O.removeClass = function(inNode,inClassName){
    inNode = O.byId(inNode);
    var t_cls;
    if(inClassName !== undefined){
        inClassName = str2array(inClassName);
        t_cls = " " + inNode["className"] + " ";
        for(var i = 0 ; i < inClassName.length; ++i){
           t_cls = t_cls.replace(" " + inClassName[i] + " ", " ");
        }
        t_cls = t_cls.trim();
    }else{
        t_cls = "";
    }
    if(inNode["className"] != t_cls){ inNode["className"] = t_cls; }
    return inNode;
}
O.toggleClass=function(inNode,inClassName,inCondition){
    inNode =O.byId(inNode);
    if(inCondition === undefined){
        inCondition = !O.hasClass(inNode, inClassName);
    }
    O[inCondition ? "addClass" : "removeClass"](inNode, inClassName);
    return inNode;
}  
O.stopEvent =function(e){
    e.preventDefault();e.stopPropagation();
}
//O.coords
//O.position  
})();